package com.angis.fx.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {

	private static final String DATABASE_NAME = "ags_fx.db";
	private static final int DATABASE_VERSION = 1;
	private static final String sqlBT = "create table BUSINESSTYPE(bid text not null, bdesc text not null, primary key (bid))";
	private static final String sqlCD = "create table CHECKDRAFT(id text not null, csid text , contitle text not null, address text, manager text," +
																"areatype text, permitcode text, permitword text, area text, areacode text, hycode text, " +
																"code text, managepos text, tel text, unittype text, jcjg text, jcsj text, jcqk text," +
																"jcjgdetail text,together text, otheruser text,whcsdutyid text, tjguid text,cslb text, " +
																"user_name text, arrivaltime text, leavetime text, dutyno text,djguid text, checkxs text, " +
																"cdrc text, checkarea text,datastatus text, tycode text, x text, y text, xlongps text, " +
																"ylatgps text, checktime text, primary key (id))";
	private static final String sqlDI = "create table DUTYINFO(dusername text not null, dutyno text not null,startdutytime text not null, enddutytime text, dutystatus text not null, mctjuuid text, aftjuuid text, mcareacode text, afareacode text, sxry text,togetheruser text,otheruser text, othercount text, cdrc text, primary key (dutyno))";
	private static final String sqlET = "create table ECNOMICTYPE(eid text not null, edesc text not null, primary key (eid))";
	private static final String sqlGZ = "create table GISZFJG(zfid text not null, userlayer text not null, x text not null, y text not null, primary key (zfid))";
	private static final String sqlQT = "create table QUICKTEXT(qid text not null, details text not null, qcreationtime text not null, creationuser text not null, primary key (qid))";
	private static final String sqlUI = "create table USERINFO(username text not null, usernamecn text, userpassword text, departmartid text, userlayer text, memberinfos text, deviceno text, primary key (username))";
	private static final String sqlWT = "create table WGTYPE(wid  text not null, conditiontype text, wgtype text, creationtime text, primary key (wid))";
	private static final String sqlWHCS = "create table WHCS(csid  text not null, contitle text not null, address text, manager text, areatype text, permitcode text, permitword text, area text, areacode text, hycode text, code text, managepos text, tel text, unittype text, x text, y text, primary key (csid))";
	private static final String sqlZT = "create table ZCTYPE(zid text not null, zconditiontype text, zwgtype text, zcreationtime text, primary key (zid))";
	private static final String sqlXT = "create table XTSZ(xid text not null, second text, meter text, host text, primary key (xid))";
	
	private static final String TABLE_BUSINESTYPE = "businesstype";
	private static final String TABLE_CHECKDRAFT = "checkdraft";
	private static final String TABLE_DUTYINFO = "dutyinfo";
	private static final String TABLE_ECNOMICTYPE = "ecnomictype";
	private static final String TABLE_GISZFJG = "giszfjg";
	private static final String TABLE_QUICKTEXT = "quicktext";
	private static final String TABLE_USERINFO = "userinfo";
	private static final String TABLE_WGTYPE = "wgtype";
	private static final String TABLE_WHCS = "whcs";
	private static final String TABLE_ZCTYPE = "zctype";
	private static final String TABLE_XTSZ = "xtsz";

	public DBHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(sqlBT);
		db.execSQL(sqlCD);
		db.execSQL(sqlDI);
		db.execSQL(sqlET);
		db.execSQL(sqlGZ);
		db.execSQL(sqlQT);
		db.execSQL(sqlUI);
		db.execSQL(sqlWT);
		db.execSQL(sqlWHCS);
		db.execSQL(sqlZT);
		db.execSQL(sqlXT);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// String sql = "drop table if exists mytable";
		// db.execSQL(sql);
		// onCreate(db);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_BUSINESTYPE);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_CHECKDRAFT);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_DUTYINFO);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_ECNOMICTYPE);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_GISZFJG);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_QUICKTEXT);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERINFO);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_WGTYPE);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_WHCS);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_ZCTYPE);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_XTSZ);
		onCreate(db);
	}
}
